//==================================================================================
//		Dual Quad Board Program
//		file name : Define.H
//		version : 1.0
//		target device : w78e516(winbond)
//		target board : dual quad board
//		c compiler : Keil
//==================================================================================

#ifndef SERIAL
#define SERIAL
#endif

#ifndef KEILC
#define KEILC
#endif


#ifdef TASKINGC

#define DATA			_data
#define PDATA			_pdat
#define IDATA			idat
#define CODE			_rom
#define REENTRANT		_reentrant
#define	AT(atpos2)		_at( atpos2 )
#define CODE_P			_rom
#define PDATA_P			_pdat
#define IDATA_P			idat
#define DATA_P			_data

#define INTERRUPT( num, name )	_interrupt(num) void name (void)

#elif defined KEILC

#define DATA		data
#define PDATA		pdata
#define IDATA		idata
#define XDATA		xdata
#define CODE		code
#define CODE_P
#define PDATA_P
#define IDATA_P
#define DATA_P

#define INTERRUPT( num, name ) name() interrupt num

#endif


//#define Quad_Costdown 1 // TW2824 costdonw

//Quad or Dual Quad Selection
//#define ch4_ch8_option 	0		//... QUAD (4Channel System)            "0" --- 4CH   "1" --- 8CH
//#define ch4_ch8_ch16_option 	2		//... Dual QUAD (8Channel System)     "0" --- 4CH   "1" --- 8CH


//... Define
//----------------------------------------------------------------
#define	SetBit(x,y)		((x) |= (y))
#define	ClearBit(x,y)		((x) &= ~(y))
#define	BitSet(x,y)		(((x)&(y))== (y))
#define	BitClear(x,y)		(((x)&(y))== 0)
#define	IfBitSet(x,y)		if(((x)&(y)) == (y))
#define	IfBitClear(x,y)	if(((x)&(y)) == 0)
//----------------------------------------------------------------
//... Key Define


//#define	FAC_RESET_KEY	0x88
//#define	A_B_KEY		11
//#define	A_KEY			31
//#define	B_KEY			32
#define	FREEZE_KEY		2
#define	MODE_KEY		18
#define	ENTER_KEY		4


#define	CH1_KEY		9
#define	CH2_KEY		10
#define	CH3_KEY		11
#define	CH4_KEY		12
#define	CH5_KEY		13
#define	CH6_KEY		14
#define	CH7_KEY		15
#define	CH8_KEY		16
#define	QUAD_KEY		19
#define	REALTIME_8CH_KEY_A	20

#define	UP_KEY			5
#define	DOWN_KEY		6
#define	LEFT_KEY		7
#define	RIGHT_KEY		8

#define	MENU_KEY		1
#define	AUTO_KEY		17
#define	ZOOM_KEY		3

#define	POLLING_6CH_KEY		21
#define	POLLING_8CH_KEY		22
#define ZOOM_TEST_KEY       23
//#define	VCR_KEY		24

/***************************************************/
#define	CH1_BIG		1
#define	CH2_BIG		2
#define	CH3_BIG		3
#define	CH4_BIG		4
#define	CH5_BIG		5
#define	CH6_BIG		6
#define	CH7_BIG		7
#define	CH8_BIG		8

/***************************************************/


#define	QUAD_A			1
#define	CH1_FULL		2
#define	CH2_FULL		3
#define	CH3_FULL		4
#define	CH4_FULL		5
#define	QUAD_B			6
#define	CH5_FULL		7
#define	CH6_FULL		8
#define	CH7_FULL		9
#define	CH8_FULL		10

#define	PIP1_MODE		11
#define	PIP2_MODE		12
#define   REALTIME_8CH	13	
#define   REALTIME_7PLUS1	16	
#define	SPLITE_2			14
#define	REALTIME_8CH_M_A	15	//one big image and seven small image mode
//#define	REALTIME_3CH		29	//three image mode
//#define 	REALTIME_5CH		30	//five image mode
//#define	QUAD_MODE		27	

#ifdef VGA_DISPLAY
//VGA CHIP
#define pvx522	
//#define TVIA_5715	

#define	VGA_800x600_60HZ		0
#define	VGA_1024x768_60HZ		1
#endif
//#define	WIN_SCRN_8CH_DLY_NTSC	200
//#define	WIN_SCRN_8CH_DLY_PAL		200
//----------------------------------------------------------------
#define	SUB_MENU_PAGE1	1
#define	SUB_MENU_PAGE2	2
#define	SUB_MENU_PAGE3	3
#define	SUB_MENU_PAGE4	4
#define	SUB_MENU_PAGE5	5
#define	SUB_MENU_PAGE6	6
#define	SUB_MENU_PAGE7	7

#define	NTSC		0
#define	PAL			1

#define	PAGE0		0
#define	PAGE1		1
#define	PAGE2		2
//==================================================================================
#define	BIT0		(0x01)
#define	BIT1		(0x02)
#define	BIT2		(0x04)
#define	BIT3		(0x08)
#define	BIT4		(0x10)
#define	BIT5		(0x20)
#define	BIT6		(0x40)
#define	BIT7		(0x80)
//following are new define for tw2835
#define	BIT8		(0x0100)
#define	BIT9		(0x0200)
#define	BIT10		(0x0400)
#define	BIT11		(0x0800)
#define	BIT12		(0x1000)
#define	BIT13		(0x2000)
#define	BIT14		(0x4000)
#define	BIT15		(0x8000)

//==================================================================================
//added for tw2835 on 07-08-08
//==================================================================================

#define   DVC_PG0      PAGE0
#define   DVC_PG1      PAGE1
#define   DVC_PG2      PAGE2

#define	ALL_CHIP	(0xd8)//(0xff)
#define	MASTER		(0x18)//(0xe7)//(0x03)
#define	SLAVE1		(0xc0)//(0x3f)//(0x0c)
//#define	SLAVE2		(0x30)
//#define	SLAVE3		(0xc0)

#define   VDO_NTSC	NTSC
#define   VDO_PAL	PAL
#define   b_cmn_jp_vdo  b_video_fmt  
#define	PTH_X			BIT0//BIT1//                
#define	PTH_Y			BIT1//BIT5//
#define	PTH_PB		BIT2//
#define	PTH_ALL		(PTH_X|PTH_Y)
//#define	__4CH__
#define	__16CH__
//#define	__WTH_ADO__

#define	cmn_dvc  		MASTER;
#define	cmn_lst_slvr_x  	MASTER;
#define	cmn_lst_slvr_y  	MASTER;
#define	cmn_max_ch = 4;//8;

//==================================================================================
//  For TW2823
#define	NULL		0
#define	ON			1
#define	OFF			0
#define	HIGH		1
#define	LOW		0

//#define   CH_16_MODE	2
//#define	CH_8_MODE		1
//#define	CH_4_MODE		0

//#define	C_PATH		BIT7
//#define	D_PATH		BIT6
//#define	ALL_PATH	(C_PATH|D_PATH)



//#define	SCALE_FULL		0xffff		//... 4/4
//#define	SCALE_QUAD	0x7fff		//... 2/4
//#define	SCALE_NINE		0x5555		//... 1/3
//#define	SCALE_PIP		0x3fff		//... 1/4
//#define	SCALE_NINE2	0xaaaa		//... 2/3
//#define	SCALE_UNIT_H	0x016c		//... (= 65536/180 = 364.09)


//----------------------------------------------------------------
//... OSD Font  for TW2824
#define	LOSS_FONT			0x4a
#define	MOTION_FONT		0x40
#define	ALARM_FONT		0x54
#define	VCR_FONT			0x68
#define	ZOOM_FONT			0x5e
#define	FREEZE_FONT		0x72

#define	PLUS_FONT			0x0b
#define	MINUS_FONT		0x0d

#define	ZERO_OFFSET		0x10
#define	ONE_OFFSET			0x11

#define	COLON_FONT		0x1a
//#define	BLANK_BOX_FONT	0x05
//#define	CHECK_BOX_FONT	0x06
//#define	BLANK_BOX_FONT	0x6a
//#define	CHECK_BOX_FONT	0x6b

//#define	CHECK_BOX_FONT	0x06

#define	LOCK_FONT			0x20

#define	UP_DOWN_FONT		0x7a
#define	LF_RG_FONT			0x7d
#define	MENU_FONT			0x77
#define	ENTER_FONT			0x74
#define	AUTO_FONT			0x02

#define	BLANK_FONT			0x00


#define	LEFT_ARROW_FONT	0x1c
#define	OSD_BAR_FONT_L	0x0a
#define	OSD_BAR_FONT_R	0x1b
#define	OSD_BAR_FONT_C	0x1d
#define	RIGHT_ARROW_FONT	0x1e

//#define	RIDIO_ON_FONT		0x3c
//#define	RIDIO_OFF_FONT	0x07
//#define	RIDIO_ON_FONT		0x90//0x69
//#define	RIDIO_OFF_FONT	0x91//0x68							
							
#define	OSD_NOR			0x00
#define	OSD_GRAY_FONT		0x02
#define	OSD_YELLOW_FONT	0x02
#define	OSD_BLINK_FONT	0x04

#define	OSD_RADIO_BLK			'#'		
#define	OSD_RADIO_CHK			'$'
#define	OSD_CHK_BOX_BLK_1		'%'         //Conflicted with "osd.h" of tw2835 (070902)
#define	OSD_CHK_BOX_CHK_1	'&'          //Conflicted with "osd.h" of tw2835 (070902)

#define	OSD_X_SMALL_1			0x5c      //Conflicted with "osd.h" of tw2835 (070902)

#define	WHITE75				0
#define	YELLOW					1
#define	CYAN					2
#define	GREEN					3
#define	MAGENTA				4
#define	RED						5
#define	BLUE					6
#define	BLACK					7
#define	WHITE100				8
#define	WHITE50				9
#define	WHITE25				10
#define	BLUE75					11
#define	BLUE_LIGHT				12

#define OSD_MODE_BMP			BIT7

#define	OSD_RD_PAGE0			0
#define	OSD_RD_PAGE1			BIT2
#define	OSD_EVEN_EN			BIT1
#define	OSD_ODD_EN			BIT0

#define	OSD_DELAY_V			4
#define	OSD_CLEAR				BIT5

//#define	OSD_INDEX_EX			BIT6	
#define	OSD_INDEX_EX			0

#define	OSD_BLINK				BIT2
#define	OSD_MIX_1				BIT3       //Conflicted with "osd.h" of tw2835 (070902)

//----------------------------------------------------------------
/*//    OSD Font for TW2835       
#define	OSD_COL_BLK			1
#define	OSD_COL_50WHT			2
#define	OSD_COL_75WHT			3
#define	OSD_COL_25WHT			4
#define	OSD_COL_100WHT		5
#define	OSD_COL_BLU			6
#define	OSD_COL_RED			7
#define	OSD_COL_ORNG			8
#define	OSD_COL_CYN			9
#define	OSD_COL_MGN			10
#define	OSD_COL_GRN			11
#define	OSD_COL_OCN			12
#define	OSD_COL_YLW			13
*/
//----------------------------------------------------------------
//... Box and Mouse Pointer for 	TW2824
/*
#define	BOX_POPUP_MAIN		15
#define	BOX_POPUP_MAIN_HL	14
#define	BOX_POPUP_SUB			13
#define	BOX_POPUP_SUB_HL		12
#define	BOX_WINDOW			11
#define	BOX_WIN_DECO			10
#define	BOX_BTN6				9
#define	BOX_BTN5				8
#define	BOX_BTN4				7
#define	BOX_BTN3				6
#define	BOX_BTN2				5
#define	BOX_BTN1				4
#define	BOX_BTN0				3
#define	BOX_BTN_CLOSE			2
#define	BOX_WIN_SLIDE1		1
#define	BOX_WIN_SLIDE0		0


#define	REG_CURCTL				0x00
#define	CUR_ON_X				BIT7
#define	CUR_ON_Y				BIT6
#define	CUR_TYPE				BIT5
#define	CUR_SUB				BIT4
#define	CUR_BLINK				BIT3
#define	CUR_HP0				BIT1
#define	CUR_VP0				BIT0

#define	REG_CUR_HP				0x01
#define	REG_CUR_VP				0x02

#define	REG_BOX_MODE			0x03
#define	BOX_TYPE				BIT7
#define	BOX_EMP				BIT6
#define	BOX_PLNEN				0x0f

#define	REG_BOX_BNDCOL		0x04
#define	OB_COL_FLAT			0xf0
#define	IB_COL_FLAT			0x0f
#define	OB_COL_LT				0xc0
#define	OB_COL_RB				0x30
#define	IB_COL_LT				0x0c
#define	IB_COL_RB				0x03

#define	REG_BOX_PLNCOL_H		0x05
#define	BOX_PLNCOL3			0xf0
#define	BOX_PLNCOL2			0x0f

#define	REG_BOX_PLNCOL_L		0x06
#define	BOX_PLNCOL1			0xf0
#define	BOX_PLNCOL0			0x0f

#define	REG_BOXCTL				0x07
#define	BOX_PATH				BIT7
#define	BOX_OBND				BIT6
#define	BOX_IBND				BIT5
#define	BOX_PLNMIX				BIT4
#define	BOX_PLNSEL				0x0c
#define	BOX_HL0				BIT1
#define	BOX_VT0				BIT0

#define	REG_BOXHL				0x08
#define	REG_BOXHW				0x09
#define	REG_BOXVT				0x0a
#define	REG_BOXVW				0x0b
*/
//----------------------------------------------------------------
//... Box avriable  for  TW2835 (070823)
#define	BOX_POP_MN			3//15
#define	BOX_POP_MN_HL			2//14
#define	BOX_POP_SB				1//13
#define	BOX_POP_SB_HL			0//12
//==================================================================================
//						Display wndwdow definition & variable description for TW2835 (070817)
//==================================================================================
#define	WNDW_DS_SC_POS_X		14
#define	WNDW_DS_SC_POS_Y		7 
#define	WNDW_DS_SC_L				17
#define	WNDW_DS_SC_H				9
#define	WNDW_DS_SC_CLOS_X		(WNDW_DS_SC_POS_X+WNDW_DS_SC_L-1)
#define	WNDW_DS_SC_CLOS_Y		(WNDW_DS_SC_POS_Y)

#define	WNDW_DS_SC_RDO_FM_X		(WNDW_DS_SC_POS_X+1)
#define	WNDW_DS_SC_RDO_FM_Y		(WNDW_DS_SC_POS_Y+2)
#define	WNDW_DS_SC_CHK_X		(WNDW_DS_SC_RDO_FM_X+1)
#define	WNDW_DS_SC_CHK_4PB_Y	(WNDW_DS_SC_RDO_FM_Y+2)
#define	WNDW_DS_SC_CHK_16PB_Y	(WNDW_DS_SC_CHK_4PB_Y+2)
#define	WNDW_DS_SC_CHK_RC_Y		(WNDW_DS_SC_CHK_16PB_Y+2)//(WNDW_DS_SC_RDO_FM_Y+6)//
//#define	WNDW_DS_SC_RDO_LS_X			(WNDW_DS_SC_RDO_FM_X+1)
//#define	WNDW_DS_SC_RDO_LS_Y			(WNDW_DS_SC_CHK_RC_Y+3)
//
//#define	SC_LOSS_BYPS				0
//#define	SC_LOSS_FRZ				1
//#define	SC_LOSS_BLAK				2
//#define	SC_LOSS_BLIK				3

#define	WNDW_DS_SC_CNT_X		(WNDW_DS_SC_CHK_X+1)
#define	WNDW_DS_SC_UNIT_X		(WNDW_DS_SC_CHK_X+4)
#define	WNDW_DS_SC_CNT_Y		11//(WNDW_DS_SC_CHK_RC_Y+2)

/*
#define	SC_FMT_1CH					0
#define	SC_FMT_4CH					1
#define	SC_FMT_4CH_PB				2
#define	SC_FMT_16CH				3
#define	SC_FMT_16CH_PB			4
#define	SC_FMT_8CH					5
#define	SC_FMT_8CH_RC				6
#define	CIF_TYPE_FR				0//0
#define	CIF_TYPE_FL				1//1
#define	MUX_TYPE_FR				2//1
#define	MUX_TYPE_FL				3//2
#define	MUX_TYPE_LV				4//0
*/
//Copy from "Wndw_ds_scrn.c" of tw2835 (070902)
#if defined(__4CH__)                                
//U8 idata	wndw_ds_sc_fmt = SC_FMT_4CH;
#elif	defined(__16CH__)
//U8 idata	wndw_ds_sc_fmt = SC_FMT_16CH;
#endif
//==================================================================================
//----------------------------------------------------------------
//... 2D Box for TW2824
/*#define	REG_2DBOX_COL			0x60
#define	_2DBOX_BNDCOL			0x30
#define	_2DBOX_PLNCOL			0x0f

#define	REG_2DBOX_CTL			0x61
#define	_2DBOX_VT0				BIT7
#define	_2DBOX_HL0				BIT6
#define	_2DBOX_MODE			BIT5
#define	_2DBOX_PATH			BIT4
#define	_2DBOX_MIX				BIT3
#define	_2DBOX_PLNEN			BIT2
#define	_2DBOX_CUREN			BIT1
#define	_2DBOX_BNDEN			BIT0

#define	REG_2DBOX_VT			0x62
#define	REG_2DBOX_HL			0x63
#define	REG_2DBOX_VW			0x64
#define	REG_2DBOX_HW			0x65

#define	REG_2DBOX_NUM			0x66
#define	_2DBOX_VNUM			0xf0
#define	_2DBOX_HNUM			0x0f

#define	REG_2DBOX_CUR_POS	0x67
#define	_2DBOX_CUR_HP			0xf0
#define	_2DBOX_CUR_VP			0x0f


#define	REG_MB_DIS				0x7e
#define	MB_DIS					0xf0

#define	REG_BLIND_CTL			0x7f
#define	BD_CELSENS				0x30
#define	BD_LVSENS				0x0f

//... Motion
#define	REG_MD_ALIGN			0x80
#define	MASK_MODE				BIT7
#define	MD_FLD					0x30
#define	MD_ALIGN				0x0f

#define	REG_MD_LVSENS			0x81
#define	MD_CELSENS				0xc0
#define	MD_LVSENS				0x1f

#define	REG_MD_SPEED			0x82
#define	MD_REFFLD				BIT7
#define	MD_SPEED				0x3f

#define	REG_MD_SPSENS			0x83
#define	MD_TMPSENS			0xf0
#define	MD_SPSENS				0x0f

#define	REG_MD_MASK_0			0x84
//----------------------------------------------------------------

//----------------------------------------------------------------
#define	REG_MCLK				0x30
#define	MCLKDEL_X				0xf0
#define	MCLKDEL_Y				0x0f

#define	REG_CLKCTL				0x5f
#define	MEM_INIT				BIT7
#define	ENCCLK_Y				BIT6
#define	ENCCLK_X				BIT5
#define	ENCCLKP_Y				BIT2
#define	ENCCLKP_X				BIT1
//----------------------------------------------------------------	

//----------------------------------------------------------------
#define	Full_Len_H				0xb4
#define	ntsc_Full_Len_V			0x78
#define	pal_Full_Len_V			0x90

#define	Quad_Len_H				0x5a
#define	ntsc_Quad_Len_V		0x3c
#define	pal_Quad_Len_V			0x48

#define	PIP_Len_H				0x2d
#define	ntsc_PIP_Len_V			0x1e
#define	pal_PIP_Len_V			0x24*/
//----------------------------------------------------------------
